def introduce(name,age):
    print(f"我叫{name}，今年{age}岁")
introduce("小明",12)


def introduce1(name,age):
    print(f"我叫{name}，今年{age}岁")
introduce(age=12,name="小明")

def greet(name,msg="Hi"):
    print(f"{msg}, {name}!")
greet("小明")

def calc_sum(*nums):
    return sum(nums)
print(calc_sum(1,2,3,4))

def print_info(**kwargs):
    print(f"name: {kwargs['name']}\nage: {kwargs['age']}")
print_info(name="小红",age=16)

def get_student():
    return  ("李华", 17, "高二")
name,age,grade = get_student()
print(name,age,grade)

def swap(a,b):
    return b,a
x,y=1,2
print(swap(x,y))

count = 0
def increment():
    global count
    count += 1  # 报错！请修正
increment()
print(count)  # 期望输出 1

def outer():
    n = 10
    def inner():
        nonlocal n # 填空
        n = 20
    inner()
    print(n)
outer()

def connect_db(host, *, port=3306, timeout=10):
    print(f"链接{host}:{port},超时{timeout}秒")
connect_db("192.168.1.1", port=5432, timeout=5)

def demo():
    a = 5
    print("局部变量:", list(locals().keys()))
demo()

def safe_divide(a, b):
    if b == 0:
        return "除数不能为0"
    else:
        return a / b
print(safe_divide(10,2))
print(safe_divide(10,0))

def print_squares(n):
    for i in range(1,n+1):
        print(i*i)
print_squares(3)

def countdown(start):
    while start >= 1:
        print(start)
        start -= 1
countdown(3)

def repeat_word(word, times=3):
    for i in range(times):
        print(word)
repeat_word("Hi")


def sum_until_zero():
    num=1
    sum1=0
    while num!=0:
        num=int(input("输入数字（输入0结束）："))
        if num!=0:
            sum1=sum1+num
        else :
            print(sum1)
sum_until_zero()

def find_max(*numbers):
    maxnum=0
    for i in numbers:
        if maxnum<i:
            maxnum=i
    return maxnum
print(find_max(3,7,2,9))


counter = 0
def increment_loop():
    global counter
    while counter < 3:
        counter += 1
        print(counter)

increment_loop()
print("最终:", counter)

def print_scores(**scores):
    for key, value in scores.items():
        print(f"{key}:{value}")
print_scores(语文=85, 数学=92, 英语=78)

def greet_until_stop(stop_word="quit"):
    while True:
        name=input("请输入名字（输入quit退出）：")
        if name==stop_word:
            print("程序结束")
            break
        print(f"Hello, {name}!")
greet_until_stop()


students = [("张三", 18), ("李四", 19), ("王五", 17)]
def print_all_students(students):
    for name, age in students:
        print(f"{name} {age}岁")
print_all_students(students)


def count_even(nums):
    count = 0
    for i in nums:
        if i % 2 == 0:
            count+=1
    print(count)
count_even([1,2,3,4,5,6])

